package com.akkainaction.cluster.wordcount.router.spring;

import akka.actor.Actor;
import akka.actor.IndirectActorProducer;
import org.springframework.context.ApplicationContext;

public class SpringActorProducer implements IndirectActorProducer {
	private final ApplicationContext applicationContext;
	private final String actorBeanName;
	private final Object[] args;
 
	public SpringActorProducer(ApplicationContext applicationContext, String actorBeanName, Object ... args) {
		this.applicationContext = applicationContext;
		this.actorBeanName = actorBeanName;
		this.args = args;
	}
 
	public Actor produce() {
		return (Actor) applicationContext.getBean(actorBeanName, args);
	}
 
	public Class<? extends Actor> actorClass() {
		return (Class<? extends Actor>) applicationContext.getType(actorBeanName);
	}
}